<?php
	//start the session
	session_start();

	//checks if user has logged in and if not displays an error message
	if(!isset($_SESSION['username']))
	{
		$_SESSION['message'] = "<span style='color: red; font-weight: bold;'>You are not logged in to view this page.</span>";
		header('Location: Login.php');
	}
?>

<!-- sort_page.php view -->

<html>
	<head>
		<title>Sorts Page</title>
		<link rel="stylesheet" type="text/css" href="css/style.css" />
	</head>
	
	<body>
		<div id="wrapper">
			<div id="banner"><img src="images/bannerv0.jpg" alt="header graphic"></div>
			<div id="wrapper_links"><?php include("menu/menu.php");?></div>
			<div id="wrapper_body">
			
				<p align="left">User: <?php echo $_SESSION['username'];?></p>

				<h3>Sort Favourites</h3>
				
				<center>
					<form class="" action="favourites_table.php" method="POST">						
						<table>
							<tr>
								<td>
									<select name="category_sort">
										
										<?php
											//defines file location
											$file = 'dropdown_data/dropdown_category_sort.txt';
											//opens file
											$options = fopen($file, 'r');
								  
											//if the file is opened activate the while loop 
											if($options)
											{
												//tests for end-of-file
   												while (!feof($options)) 
												{
													//gets the options located in the text file
													$line = fgets($options);
													
													$temp = explode(' |', $line);
													
													//outputs the options into the dropdown menu
													echo '<option name="' . $temp[0] . '" id="' . $temp[0] . '">' . $temp[0] . '</option>' . "<br />";
   												}
   										
											 	fclose($options);
											}
										?>
						
									</select>
										
									<select name="sort_by">
											
										<?php
											//defines file location
											$file = 'dropdown_data/dropdown_sort_by.txt';
											//opens file
											$options = fopen($file, 'r');
								  
											//if the file is opened activate the while loop 
											if($options)
											{
												//tests for end-of-file
												while (!feof($options)) 
												{
													//gets the options located in the text file
													$line = fgets($options);
														
													$temp = explode(' |', $line);
														
													//outputs the options into the dropdown menu
													echo '<option name="' . $temp[0] . '" id="' . $temp[0] . '">' . $temp[0] . '</option>' . "<br />";
												}
   										
												fclose($options);
											}
										?>
											
									</select>
								</td>	
							</tr>
						</table>
						<input type="submit" name="submit" id="submit" value="Submit" />	
					</form> 
				</center>
				
				<?php
					//outputs the error/confirmation message from the favourites_page.php script on this page
					if(isset($_SESSION['message']))
					{
						echo $_SESSION['message'] . '<br />';
					}
				?>
					
			</div>
		</div>
	</body>
</html>